package produce.controller;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Kevin
 * @date 2023/6/11 12:53
 * @description 工作队列模式消息
 * 一对多
 **/
@RequestMapping("/work")
@RestController
public class WorkController {

  @Autowired
  private RabbitTemplate rabbitTemplate;

  /**
   * 发送30条消息，消费者1和消费者2的消费比例是2:1
   * @return
   */
  @GetMapping
  public String send(){

    for (int i = 0; i < 30; i++) {
      rabbitTemplate.convertAndSend("","work-queue",i);
    }

    return "发送工作模式消息成功";
  }


}
